package com.jason.canvas.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;

/**
 * @DESC: Path的使用
 * @Author: Jason
 * @Date: 16/9/18
 * @Time: 22:25
 */

public class PathView5 extends View {

    private Path mPath; // 路径对象
    private Paint mPaint; // 画笔对象

    public PathView5(Context context, AttributeSet attrs) {
        super(context, attrs);

        // 实例化画笔
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeWidth(10);
        mPaint.setColor(Color.CYAN);

        // 实例化路径
        mPath = new Path();

        // 移动点至[300, 300]  当我们没有移动Path的点时，其默认的起点为画布的[0,0]点
        mPath.moveTo(300, 300);

        // 连接路径到点[100, 100]
        mPath.lineTo(100, 100);

    }

    @Override
    protected void onDraw(Canvas canvas) {
        // 绘制路径
        canvas.drawPath(mPath, mPaint);
    }
}
